package name.jiaosha.air.company.controller;

import java.util.List;

import name.jiaosha.air.OperateTip;
import name.jiaosha.air.company.domain.Company;
import name.jiaosha.air.company.domain.Department;
import name.jiaosha.air.company.service.ICompanyService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller("departmentController")
public class DepartmentController {
	@Autowired
	private ICompanyService companyService;

	public OperateTip create(Department department) {

		Company company = companyService.getCompanyById(1);
		department.setCompany(company);
		companyService.createDepartment(department);

		OperateTip tip = new OperateTip("1", "操作成功");
		return tip;
	}
	
	public OperateTip update(Department department) {

		Department d=companyService.getDepartmentById(department.getId());
		d.setName(department.getName());
		companyService.updateDepartment(department);

		OperateTip tip = new OperateTip("1", "操作成功");
		return tip;
	}
	
	public Department getDepartmentById(int id){
		
		return companyService.getDepartmentById(id);
	}

	public List<Department> getMyDepartmentList() {

		List<Department> list = companyService.getDepartmentByComId(null);

		return list;
	}
}
